package com.netty.demoOther;

import java.util.Random;
import java.util.concurrent.*;

/**
 * Created by Lxk on 2019/4/27.
 */

class Person {
    private String name;

    private String pwd;

    private Integer age;

    public Person(String name, String pwd, Integer age) {
        this.name = name;
        this.pwd = pwd;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

public class Test {

    public static void main(String[] args){
//        Set<Person> set = new HashSet<>();
//        Person p1 = new Person("唐僧","pwd1",25);
//        Person p2 = new Person("孙悟空","pwd2",26);
//        Person p3 = new Person("猪八戒","pwd3",27);
//        set.add(p1);
//        set.add(p2);
//        set.add(p3);
//        System.out.println("总共有" + set.size() + "个元素");
//        p3.setAge(2);
//        set.remove(p3);
//        set.add(p3);
//        System.out.println("总共有" + set.size() + "个元素");
//        for(Person person : set){
//            System.out.println(person);
//        }
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        for(int i = 0; i < 10; i++){
            Future<Integer> res = executor.submit(new Callable<Integer>() {
                @Override
                public Integer call() throws Exception {
                    Random rand = new Random(100);
                    Integer val = rand.nextInt(100);
                    System.out.println("Thread : " + Thread.currentThread().getName()+ " run: " + val);
                    try{
                        Thread.sleep(1000);
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                    return val;
                }
            });
            try {
                System.out.println("res: " + res.get());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
